//
//  TitleStyleView.m
//  JiaoX
//
//  Created by yinqy on 15/3/3.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//  用于帖子列表，帖子标题，前面，显示置顶或者精华

#import "TitleStyleView.h"
#define TITLE_FONT [UIFont systemFontOfSize:[DimensUtils getScaleX:12]]

@implementation TitleStyleView

-(void)setTitleStyles:(NSArray *)styles{
    [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self setSize:[TitleStyleView sizeWithTitleStyles:styles]];
    CGFloat X = 0;
    for (int i = 0; i<styles.count; i++) {
        TitleStyle *titleStyle = styles[i];
        UILabel *label = [[UILabel alloc]init];
        [label setText:titleStyle.labelFront];
        [label setTextAlignment:NSTextAlignmentCenter];
        [label setFont:TITLE_FONT];
        [label setTextColor:[UIColor whiteColor]];
        [label setBackgroundColor:[UIColor colorWithHexString:titleStyle.labelColor]];
        [label setSize:CGSizeMake([titleStyle.labelFront sizeWithFont:TITLE_FONT].width+8, self.height)];
        [label setX:X];
        [label setY:0];
        X += label.width+5;
        [self addSubview:label];
    }
}

+(CGSize)sizeWithTitleStyles:(NSArray *)titleStyles{
    if (titleStyles==nil || titleStyles.count==0) {
        return CGSizeZero;
    }
    CGFloat height = [UIFont systemFontOfSize:[DimensUtils getScaleX:14]].lineHeight;
    CGFloat width = 0;
    
    for (int i = 0; i<titleStyles.count; i++) {
        TitleStyle *titleStyle = titleStyles[i];
        width += [titleStyle.labelFront sizeWithFont:TITLE_FONT].width+8+5;
    }
    width -= 5;
    return CGSizeMake(width, height);
}


@end
